package com.igeek.boot.service;

import com.igeek.boot.constant.RedisMessageConstant;
import com.igeek.boot.entity.LoginVO;
import io.netty.util.internal.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * @Author fengqq
 * @Description TODO
 * @Date 2024/9/5  10:01
 */
@Service
@Slf4j
public class MemberService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    public String login(LoginVO loginVO) {
        if(ObjectUtils.isEmpty(loginVO)){
            return null;
        }
        //获取登录页面中的手机号 输入的验证码
        String phone = loginVO.getPhone();
        String inputCode = loginVO.getCode();
        log.info("inputCode:{}",inputCode);
        //从redis获取验证码 18115161666_001_code
        String redisCode =
                stringRedisTemplate.opsForValue().get(phone + "_" + RedisMessageConstant.SENDTYPE_LOGIN + "_" + inputCode);
        log.info("redisCode:{}",redisCode);
        //将redis获取验证码 和 用户输入的进行比较
        if(StringUtils.hasLength(redisCode) && StringUtils.hasLength(inputCode)){
            if(inputCode.equals(redisCode)){
                return "tokenxxxxxx";
            }
        }
        return null;

    }
}
